import { defineStore } from 'pinia'
import { ssrContextKey } from 'vue'
import { getDictionaryList } from '../../api/dictionary'
import { getOrderPageList } from '../../api/qqOrder'
import { Dictionary } from '../../types/dictionary'
import { Order } from '../../types/qqOrder'
import { QuickResponseData } from '../../utils/request'

interface OrderState {
  orderList: Array<Order>
  dictionaryList: Array<Dictionary>
}
export const useOrderStore = defineStore('orderStore', {
  state: (): OrderState => {
    return {
      orderList: [],
      dictionaryList: [],
    }
  },
  getters: {},
  actions: {
    getDictionaryList(dicTypeId: string): Promise<Array<Dictionary>> {
      return new Promise((resolve) => {
        getDictionaryList(dicTypeId).then((res) => {
          const { data: dictionaryList } = res
          this.dictionaryList = dictionaryList
          resolve(dictionaryList)
        })
      })
    },
    getOrderPageList(parmas: object): Promise<QuickResponseData<Array<Order>>> {
      return new Promise((resolve) => {
        getOrderPageList(parmas).then((res) => {
          const { data: orderList } = res
          this.orderList = orderList
          resolve(res)
        })
      })
    },
  },
  persist: {
    enabled: true,
  },
})
